<%@include  file="/WEB-INF/header.jsp"%>
<%@include  file="/WEB-INF/jsp/user_update.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
     <!-- 用户列表  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">用户管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->

		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newCateDialog" >新建</a>
		<div class="row">
			<div class="col-lg-12">

					
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>序号</th>
								<th>用户名</th>
								<th>密码</th>
								<th>权限</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							
								<c:forEach items="${ulist}" var="u" varStatus="i">
								<tr>
									<td>${u.user_id }</td>
									<td>${u.user_name }</td>
									<td>${u.user_pass }</td>
									<td>${u.user_rank }</td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#editModal" role="button" onclick="edit('${u.user_name }')">修改</a>
										<a href="${pageContext.request.contextPath }/user/delU.action?username=${u.user_name }" class="btn btn-danger btn-xs" role="button" onclick="JavaScript:return confirm('确实要删除该用户信息吗？')">删除</a>
									</td>
								</tr>
								</c:forEach>
						
						</tbody>
					</table>
					

			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 用户列表  end-->
</div>

<form class="form-horizontal" id="new_user_form">
<div class="modal fade" id="newCateDialog" tabindex="-1" role="dialog"
	 aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建用户信息</h4>
			</div>
			<div class="modal-body">

					<div class="form-group">
						<label for="new_username" class="col-sm-2 control-label">
							用户名：
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_username" placeholder="请输入用户名" name="user_name" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_pass" class="col-sm-2 control-label">密码：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_pass" placeholder="请输入密码" name="user_pass" />
						</div>
					</div>


			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="addUser412()">创建用户</button>
			</div>

		</div>
	</div>
</div>
</form>
<script>
//通过id获取修改的商品信息
function editCate(cate_id) {
	alert("ccc");
	$.post("${pageContext.request.contextPath}/category/getCateById.action",{"cate_id":cate_id},function(data){
		 $("#edit_cate_id").val(data.cate_id);
         $("#edit_cateName").val(data.cate_name);
         $("#edit_cateDesc").val(data.cate_desc);

         if(data.parentid==0){
        	 $("#form_parentid").hide();
        	 $("#form_cateDesc").show();
        	 
         }else{
        	 $("#form_parentid").show();
        	 $("#form_cateDesc").hide();
        	 $("select option[value='"+data.parentid+"']").attr("selected", "selected");  
         }
	});
}
// 执行修改用户操作
function updateUser() {
	
	$.post("${pageContext.request.contextPath}/user/getUpdateuser.action",$("#editUserModal").serialize(),function(data){
		if(data =="OK"){
			alert("商品分类信息更新成功！");
			window.location.reload();
		}else{
			alert("商品分类信息更新失败！aaa");
			window.location.reload();
		}
	});
}
//执行修改的显示原名字
function edit(username){
	alert(username);
	$.post("${pageContext.request.contextPath}/user/getUserByName.action",{"username":username},function(data){
		alert("==="+data);
		$("#username").val(data.user_name);
		$("#password").val(data.user_pass);
		$("#user_id").val(data.user_id);
	},"json");
}

function addUser412() {
	alert("ccc");
	$.post("${pageContext.request.contextPath}/user/addUser412.action",
			$("#new_user_form").serialize(),function(data){
				if(data =="OK"){
					alert("用户创建成功！");
					window.location.reload();
				}else{
					alert("用户创建失败！");
					window.location.reload();
				}

			});
}
</script>

 <%@include  file="/WEB-INF/footer.jsp"%>